import { reactive } from "vue";
import { formRules } from "./rule";

interface FormItemProps {
  /** 资讯ID */
  id?: number;
  /** 资讯标题 */
  title: string;
  /** 资讯分类 */
  categoryId: number;
  /** 资讯标签 */
  tags: string[];
  /** 封面图片 */
  coverImage?: string;
  /** 资讯摘要 */
  summary?: string;
  /** 资讯内容 */
  content: string;
  /** 作者 */
  author?: string;
  /** 来源 */
  source?: string;
  /** 发布状态 */
  status: number;
  /** 是否置顶 */
  isTop: boolean;
  /** 是否推荐 */
  isRecommend: boolean;
  /** 排序值 */
  sort: number;
  /** 阅读量 */
  viewCount?: number;
  /** 点赞数 */
  likeCount?: number;
  /** 评论数 */
  commentCount?: number;
  /** 发布时间 */
  publishTime?: string;
  /** 备注 */
  remark?: string;
  /** 创建时间 */
  createTime?: string;
  /** 更新时间 */
  updateTime?: string;
}

interface FormProps {
  formInline: FormItemProps;
}

/** 资讯状态枚举 */
enum NewsStatus {
  /** 草稿 */
  DRAFT = 0,
  /** 已发布 */
  PUBLISHED = 1,
  /** 已下架 */
  OFFLINE = 2
}

/** 资讯状态文本映射 */
export const NewsStatusText = {
  [NewsStatus.DRAFT]: "草稿",
  [NewsStatus.PUBLISHED]: "已发布",
  [NewsStatus.OFFLINE]: "已下架"
};

/** 资讯状态选项 */
export const newsStatusOptions = [
  { label: "草稿", value: NewsStatus.DRAFT },
  { label: "已发布", value: NewsStatus.PUBLISHED },
  { label: "已下架", value: NewsStatus.OFFLINE }
];

/** 资讯分类选项 */
export const newsCategoryOptions = [
  { label: "乒乓球新闻", value: 1 },
  { label: "赛事资讯", value: 2 },
  { label: "技术教学", value: 3 },
  { label: "装备评测", value: 4 },
  { label: "俱乐部动态", value: 5 },
  { label: "行业动态", value: 6 },
  { label: "其他", value: 99 }
];

/** 资讯标签选项 */
export const newsTagOptions = [
  { label: "热门", value: "热门" },
  { label: "推荐", value: "推荐" },
  { label: "精选", value: "精选" },
  { label: "原创", value: "原创" },
  { label: "转载", value: "转载" },
  { label: "视频", value: "视频" },
  { label: "图文", value: "图文" },
  { label: "专题", value: "专题" },
  { label: "赛事", value: "赛事" },
  { label: "教学", value: "教学" },
  { label: "装备", value: "装备" },
  { label: "技巧", value: "技巧" }
];

/** 资讯来源选项 */
export const newsSourceOptions = [
  { label: "原创", value: "原创" },
  { label: "新华网", value: "新华网" },
  { label: "人民网", value: "人民网" },
  { label: "央视网", value: "央视网" },
  { label: "中国体育报", value: "中国体育报" },
  { label: "乒乓世界", value: "乒乓世界" },
  { label: "国际乒联", value: "国际乒联" },
  { label: "中国乒协", value: "中国乒协" },
  { label: "其他", value: "其他" }
];

/** 获取分类名称 */
export function getCategoryName(categoryId: number): string {
  const category = newsCategoryOptions.find(item => item.value === categoryId);
  return category ? category.label : "未知分类";
}

/** 获取状态标签类型 */
export function getStatusTagType(status: number): string {
  switch (status) {
    case NewsStatus.DRAFT:
      return "info";
    case NewsStatus.PUBLISHED:
      return "success";
    case NewsStatus.OFFLINE:
      return "danger";
    default:
      return "";
  }
}

export type { FormItemProps, FormProps };
export { NewsStatus };